<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="redhat,VirtualBox," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.2" />






<meta name="description" content="个人电脑上虚拟机一直使用VMware WorkStation，该软件是收费的，现更换免费小巧的虚拟机软件VitualBox，这里记录一下网络设置的一种方式。">
<meta property="og:type" content="article">
<meta property="og:title" content="VitualBox使用Host Only方式配置RedHat连接网络">
<meta property="og:url" content="https://my.oschina.net/u/588736/blog/2016/11/01/VitualBox_RedHat_hostonly/index.html">
<meta property="og:site_name" content="晚来风">
<meta property="og:description" content="个人电脑上虚拟机一直使用VMware WorkStation，该软件是收费的，现更换免费小巧的虚拟机软件VitualBox，这里记录一下网络设置的一种方式。">
<meta property="og:image" content="http://7xvh4i.com1.z0.glb.clouddn.com/49375023.jpg">
<meta property="og:updated_time" content="2016-11-28T09:56:24.897Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="VitualBox使用Host Only方式配置RedHat连接网络">
<meta name="twitter:description" content="个人电脑上虚拟机一直使用VMware WorkStation，该软件是收费的，现更换免费小巧的虚拟机软件VitualBox，这里记录一下网络设置的一种方式。">
<meta name="twitter:image" content="http://7xvh4i.com1.z0.glb.clouddn.com/49375023.jpg">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="https://my.oschina.net/u/588736/blog/2016/11/01/VitualBox_RedHat_hostonly/"/>


  <title> VitualBox使用Host Only方式配置RedHat连接网络 | 晚来风 </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">晚来风</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">林花谢了春红，太匆匆。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                VitualBox使用Host Only方式配置RedHat连接网络
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-11-01T00:00:00+08:00" content="2016-11-01">
              2016-11-01
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Linux/" itemprop="url" rel="index">
                    <span itemprop="name">Linux</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>个人电脑上虚拟机一直使用VMware WorkStation，该软件是收费的，现更换免费小巧的虚拟机软件VitualBox，这里记录一下网络设置的一种方式。</p>
<a id="more"></a>
<h2 id="设置步骤"><a href="#设置步骤" class="headerlink" title="设置步骤"></a>设置步骤</h2><h3 id="安装virtualbox之后它会在宿主机上面安装一个虚拟网卡"><a href="#安装virtualbox之后它会在宿主机上面安装一个虚拟网卡" class="headerlink" title="安装virtualbox之后它会在宿主机上面安装一个虚拟网卡"></a>安装virtualbox之后它会在宿主机上面安装一个虚拟网卡</h3><p>打开cmd，查看ip信息<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">&gt; ipconfig</div><div class="line">以太网适配器 VirtualBox xxx Network:</div><div class="line"></div><div class="line">   连接特定的 DNS 后缀 . . . . . . . :</div><div class="line">   本地链接 IPv6 地址. . . . . . . . : fe80::4d64:fc7c:75e0:9db9%20</div><div class="line">   IPv4 地址 . . . . . . . . . . . . : 192.168.137.1</div><div class="line">   子网掩码  . . . . . . . . . . . . : 255.255.255.0</div><div class="line">   默认网关. . . . . . . . . . . . . :</div></pre></td></tr></table></figure></p>
<h3 id="虚拟机上面配置网络使用的是host-only方式"><a href="#虚拟机上面配置网络使用的是host-only方式" class="headerlink" title="虚拟机上面配置网络使用的是host-only方式"></a>虚拟机上面配置网络使用的是host-only方式</h3><p><img src="http://7xvh4i.com1.z0.glb.clouddn.com/49375023.jpg" alt=""></p>
<h3 id="本机（宿主机）设置"><a href="#本机（宿主机）设置" class="headerlink" title="本机（宿主机）设置"></a>本机（宿主机）设置</h3><p>修改已连接的网络属性，设置共享（选择共享给虚拟网卡）</p>
<h3 id="虚拟机设置"><a href="#虚拟机设置" class="headerlink" title="虚拟机设置"></a>虚拟机设置</h3><h4 id="1-修改ip"><a href="#1-修改ip" class="headerlink" title="1.修改ip"></a>1.修改ip</h4><h5 id="etc-sysconfig-network-scripts-ifcfg-eth0"><a href="#etc-sysconfig-network-scripts-ifcfg-eth0" class="headerlink" title="/etc/sysconfig/network-scripts/ifcfg-eth0"></a>/etc/sysconfig/network-scripts/ifcfg-eth0</h5><figure class="highlight sh"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">DEVICE=<span class="string">"eth0"</span></div><div class="line">BOOTPROTO=<span class="string">"static"</span> <span class="comment">#这里改为使用静态ip</span></div><div class="line">HWADDR=<span class="string">"08:00:27:0C:33:8F"</span></div><div class="line">NM_CONTROLLED=<span class="string">"yes"</span></div><div class="line">ONBOOT=<span class="string">"yes"</span> <span class="comment">#设置为自动启动</span></div><div class="line">TYPE=<span class="string">"Ethernet"</span></div><div class="line">UUID=<span class="string">"f4adafbc-322d-4dc8-b549-4291f1c04f01"</span></div><div class="line">IPADDR=192.168.137.110 <span class="comment">#设置该虚拟机的ip地址，要与宿主机在一个网段，但是不能重名</span></div><div class="line">NETMASK=255.255.255.0 <span class="comment">#设置子网掩码</span></div></pre></td></tr></table></figure>
<h4 id="修改网关"><a href="#修改网关" class="headerlink" title="修改网关"></a>修改网关</h4><h5 id="etc-sysconfig-network"><a href="#etc-sysconfig-network" class="headerlink" title="/etc/sysconfig/network"></a>/etc/sysconfig/network</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">NETWORKING=yes</div><div class="line">HOSTNAME=yourhostname</div><div class="line">GATEWAY=192.168.137.1 #这里设置网关，也就是那个虚拟网卡的ip</div></pre></td></tr></table></figure>
<h4 id="修改DNS"><a href="#修改DNS" class="headerlink" title="修改DNS"></a>修改DNS</h4><h5 id="etc-resolv-conf"><a href="#etc-resolv-conf" class="headerlink" title="/etc/resolv.conf"></a>/etc/resolv.conf</h5><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">nameserver xxx.xxx.xxx.xxx</div></pre></td></tr></table></figure>
<p>可以在本地打开cmd，输入<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">nslookup www.baidu.com</div></pre></td></tr></table></figure></p>
<p>查看</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">C:\Users\lenovo&gt;nslookup www.badiu.com</div><div class="line">服务器:  public1.114dns.com</div><div class="line">Address:  114.114.114.114</div></pre></td></tr></table></figure>
<h4 id="重启network"><a href="#重启network" class="headerlink" title="重启network"></a>重启network</h4><h5 id="执行命令：service-network-restart"><a href="#执行命令：service-network-restart" class="headerlink" title="执行命令：service network restart"></a>执行命令：service network restart</h5><p>可能出现的错误：Device eth0 does not seem to be present</p>
<p>解决：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"># rm -rf /etc/udev/rules.d/70-persistent-net.rules</div><div class="line"># reboot</div><div class="line"></div><div class="line"># cat /etc/udev/rules.d/70-persistent-net.rules</div><div class="line"></div><div class="line">//修改网卡地址与网卡编号一致即可</div><div class="line"># vim /etc/sysconfig/network-scripts/ifcfg-eth0</div><div class="line"></div><div class="line">DEVICE=?</div><div class="line">HWADDR=&quot;?&quot;</div></pre></td></tr></table></figure></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/redhat/" rel="tag">#redhat</a>
          
            <a href="/tags/VirtualBox/" rel="tag">#VirtualBox</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/10/27/nginx+tomcat_loadbalance/" rel="next" title="简单测试 Nginx + Tomcat 实现负载均衡">
                <i class="fa fa-chevron-left"></i> 简单测试 Nginx + Tomcat 实现负载均衡
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/11/02/rsync_backup/" rel="prev" title="rsync实现文件备份同步">
                rsync实现文件备份同步 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="LenhartG" />
          <p class="site-author-name" itemprop="name">LenhartG</p>
          <p class="site-description motion-element" itemprop="description">美国《时代周刊》2006年度风云人物</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">38</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">14</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">25</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/gxjares" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/u/2526255830" target="_blank" title="Weibo">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                  Weibo
                </a>
              </span>
            
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#设置步骤"><span class="nav-number">1.</span> <span class="nav-text">设置步骤</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装virtualbox之后它会在宿主机上面安装一个虚拟网卡"><span class="nav-number">1.1.</span> <span class="nav-text">安装virtualbox之后它会在宿主机上面安装一个虚拟网卡</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#虚拟机上面配置网络使用的是host-only方式"><span class="nav-number">1.2.</span> <span class="nav-text">虚拟机上面配置网络使用的是host-only方式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#本机（宿主机）设置"><span class="nav-number">1.3.</span> <span class="nav-text">本机（宿主机）设置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#虚拟机设置"><span class="nav-number">1.4.</span> <span class="nav-text">虚拟机设置</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1-修改ip"><span class="nav-number">1.4.1.</span> <span class="nav-text">1.修改ip</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#etc-sysconfig-network-scripts-ifcfg-eth0"><span class="nav-number">1.4.1.1.</span> <span class="nav-text">/etc/sysconfig/network-scripts/ifcfg-eth0</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#修改网关"><span class="nav-number">1.4.2.</span> <span class="nav-text">修改网关</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#etc-sysconfig-network"><span class="nav-number">1.4.2.1.</span> <span class="nav-text">/etc/sysconfig/network</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#修改DNS"><span class="nav-number">1.4.3.</span> <span class="nav-text">修改DNS</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#etc-resolv-conf"><span class="nav-number">1.4.3.1.</span> <span class="nav-text">/etc/resolv.conf</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#重启network"><span class="nav-number">1.4.4.</span> <span class="nav-text">重启network</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#执行命令：service-network-restart"><span class="nav-number">1.4.4.1.</span> <span class="nav-text">执行命令：service network restart</span></a></li></ol></li></ol></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div>
<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="http://music.163.com/outchain/player?type=2&id=208889&auto=1&height=66"></iframe>
</div>
<div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">LenhartG</span>
</div>

<!--
<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>
-->

<!--
<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>
-->
        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  



  




  
  

  

  

  

  


</body>
</html>
